﻿using BLL;
using DAL;
using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Flowers.Controllers
{
    public class FlowersStrockController : Controller
    {
        //
        // GET: /FlowersStrock/
        IFactory<IFlowersModel, FlowerModels> bll = new Factory<IFlowersModel, FlowerModels>();
        IFactory<IShoppingModel, ShopingTables> bll1 = new Factory<IShoppingModel, ShopingTables>();
        /// <summary>
        /// 商城显示
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string FlowersGiftsType=null, string FlowersStockType=null)
        {
            
            //TempData["user"] = "1111111";
            //Session["uid"] = 2;
            ViewBag.lis = bll.Fbll().getFlower(FlowersGiftsType, FlowersStockType);
            return View();
        }
        /// <summary>
        /// 显示购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult ShopCar()
        {
            int UserId = 0;
            if(Session["user"]!=null)
            {
                UserId = (Session["user"] as Model.UserModel).UserID;
            }
            else
            {
                return Redirect("/Behavior/Login");
            }
            //int UserId = 1;
            var list = bll1.Fbll().getshop(UserId);
            return View(list);
        }
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public int AddshopCar(Model.ShoppingModel shop)
        {
            if (Session["user"] != null)
            {
                shop.UserID = (Session["user"] as Model.UserModel).UserID;
            }
            else
            {
                return -1;
            }
            //shop.UserID = 1;
            var ii = bll1.Fbll().AddShopingCar(shop);
            return ii;
        }
        /// <summary>
        /// 进行购物车数量的更新
        /// </summary>
        /// <param name="shopid"></param>
        /// <param name="sums"></param>
        /// <returns></returns>
        public int update(int shopid,int sums)
        {
            var ii = bll1.Fbll().UpdateShoping(shopid, sums);
            return ii;
        }
        /// <summary>
        /// 删除购物车信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult deleteF(int id)
        {
            if (Session["user"] == null)
            {
                return Redirect("/Behavior/Login");
            }
            var ii = bll1.Fbll().removeShopingCar(id.ToString());

            return Content("<script>location.href='/FlowersStrock/ShopCar'</script>");
        }
    }
}
